<?php

	class mailinglistmodule {
		function name() { return 'Mailing List Module'; }
		function description() { return 'Mailing List module, for mailing list management'; }
		function author() { return 'Immanuel192'; }

		function hasSources() { return true; }
		function hasContent() { return false; }
		function hasViews() { return true; }

		/*function forceLocation() { 
			$loc=null;
			$loc->mod="mailinglistmodule";
			$loc->src="@".$loc->mod;
			$loc->int="";
			return $loc;
		}
*/

		function supportsWorkflow() { return false; }

		function permissions($internal = '') {
			return array(
			'administrate'=>"Administrate",
			'manage'=>"Manage Email",
			'mail'=>"Send mailling list",
			'delete'=>"Delete Email",
			);
		}

		function show($view,$loc = null, $title = '') {
			global $db;
			mailinglistmodule::install();
            $config=$db->selectObject("mailinglistmodule_config","location_data='".serialize($loc)."'");
            
			$template = new template('mailinglistmodule',$view,$loc);
			$template->register_permissions(array('administrate',"mail"),$loc);
			// Assign page data
            $template->assign('config', $config);
			$template->assign('moduletitle', $title);
			$template->output();
		}
		function install()
		{
			global $db;
			$sql_mail="CREATE TABLE IF NOT EXISTS {$db->prefix}maillinglist(
			email text,
			id int(10) NOT NULL AUTO_INCREMENT,
			users_id int(11) DEFAULT NULL,
			blacklist int(1) DEFAULT '0',
			email_id int(11) DEFAULT NULL,
			PRIMARY KEY(id)
			)";
			@mysqli_query($db->connection,$sql_mail);
		}
		function deleteIn($loc) {
			return false;
		}

		function copyContent($oloc,$nloc) {
			global $db;
			return false;
		}

		function searchName() {
			return false;
		}

		function spiderContent($item = null) {
			return false;
		}
        
        function SendMail($subject, $content, $format=0, $receive=array(), $dont_add_admin=false,$from_mail,$from){
            // send email to admin 
            $headers['From'] =  $from_mail ;
            $headers['Reply-to'] = $from_mail;

            require_once(BASE.'subsystems/mail.php');
            $mail = null;
            $mail = new exponentMail();

            if ($dont_add_admin==false)
                $mail->addTo($from_mail);
            if (!is_array($receive))
            {
                $receive=array($receive);
            }
            foreach ($receive as $v)
                $mail->addTo($v);

            $mail->subject($subject);
            if ($format == 0)
                $mail->addText($content);
            else
                $mail->addHTML($content);
            $mail->addHeaders($headers);
            $mail->addFrom($from_mail, $from );
            try{
                @$mail->send();
                return true;
            }
            catch (Exception $e){
                return false;
            }
        }
	}

?>
